#!/usr/bin/php
<?php

Class Advert_Import
{
#var $production;
var $development;

function Advert_Import()
{
## PREPARE CONNECTION ##
/*
$this->production=mysql_connect("localhost","infopark_com_ua","8888zG6Wtv1k",true);
mysql_set_charset ('utf8',$this->production);
mysql_select_db("infopark_com_ua",$this->production);
*/
$this->development=mysql_connect("localhost","infopark_com_ua","8888zG6Wtv1k",true);
mysql_set_charset ('utf8',$this->development);
mysql_select_db("dev_infopark_com_ua",$this->development);

$this->get_subcategory();
}
function get_subcategory()
{
$sql="SELECT tid FROM taxonomy_term_hierarchy WHERE parent=238";
$node_advert_terms_id=5;

$terms=$this->LIST_Q($sql,$this->development);
foreach($terms as $term)
  {
   $sql1="SELECT * FROM node_advert_terms_taxonomy WHERE tid=".$this->Q($term->tid); 
   if(mysql_num_rows($this->QUERY($sql1,$this->development))>0)
    {
    $sql2="UPDATE node_advert_terms_taxonomy SET node_advert_terms_id=".$node_advert_terms_id." WHERE tid=".$term->tid;
    }else{
    $sql2="INSERT INTO node_advert_terms_taxonomy (tid,node_advert_terms_id) VALUES (".$term->tid.",".$node_advert_terms_id.")";
    }
    $this->QUERY($sql2,$this->development);
    print $sql2."\n\n";
  }
}
function Q($str,$string=0)
{
return ($string?"'":"").mysql_escape_string($str).($string?"'":"");
}
function QUERY($sql,$conn)
{
$result=mysql_query($sql,$conn);
return $result;
}
function ROW_Q($sql,$conn)
{
$result=$this->QUERY($sql,$conn);
$r=mysql_fetch_object($result);
if(count($r)==0)$r=false;
return $r;
}
function LIST_Q($sql,$conn)
{

$result=$this->QUERY($sql,$conn);
while($r=mysql_fetch_object($result))
  {
  $data[]=$r;
  }
  
  if(count($data)==0)$data=false;
  return $data;
}

}
function pre($array)
{
print_r($array);
}
$AI=new Advert_Import;

?>